package com.example.perpetualcalendar.ui.fragment.joke;



import androidx.annotation.NonNull;

import com.example.perpetualcalendar.data.Api;
import com.example.perpetualcalendar.data.network.CommonRetrofit;
import com.example.perpetualcalendar.domain.entity.Joke;
import com.example.perpetualcalendar.domain.entity.JokeRequest;
import com.example.perpetualcalendar.domain.repository.ApiJoke;


import java.util.HashMap;

import io.reactivex.Observable;

public class JokeRepository extends CommonRetrofit<Api> implements ApiJoke {

    public JokeRepository() {
    }

    @NonNull
    @Override
    protected Class<Api> getRestClass() {
        return Api.class;
    }

    @NonNull
    @Override
    public Observable<Joke> jokeApi() {
        JokeRequest request = new JokeRequest();
        HashMap<String, Object> map = new HashMap<>();
        map.put("sort",request.getSort());
        map.put("page",request.getPage());
        map.put("pagesize",request.getPagesize());
        map.put("time",request.getTime());
        map.put("key",request.getKey());
        Observable<Joke> joke = getNetworkService().getJoke(map);
        return joke.map(data-> data);
    }
}
